import { ClassSerializerInterceptor, DynamicModule, Module } from '@nestjs/common'
import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core'
import { ResponseExceptionFilter } from './response-exception.filter'
import { ResponseSerializerInterceptor } from './response-serializer.interceptor'

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: ClassSerializerInterceptor,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: ResponseSerializerInterceptor,
    },
    {
      provide: APP_FILTER,
      useClass: ResponseExceptionFilter,
    },
  ],
})
export class ResponseSerializerModule {
  static forRoot(): DynamicModule {
    return {
      module: ResponseSerializerModule,
    }
  }
}
